/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.database;

import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;

public class SituationCursor extends SQLiteCursor {

	private static final String[] mColumns = { DBAdapter.DB_Situation_ID, DBAdapter.DB_Situation_Name, DBAdapter.DB_Situation_Active };
	
	public static SituationCursor queryAll(SQLiteDatabase mDb) {
		return (SituationCursor) mDb.queryWithFactory(new Factory<SituationCursor>(SituationCursor.class), true, DBAdapter.DB_Situation, mColumns, null, null, null, null, null, null);
	}
	
	public static SituationCursor query(SQLiteDatabase mDb, int sid) {
		final String select  = DBAdapter.DB_Situation_ID + " = " + sid;
		return (SituationCursor) mDb.queryWithFactory(new Factory<SituationCursor>(SituationCursor.class), true, DBAdapter.DB_Situation, mColumns, select, null, null, null, null, null);
	}
	
	private int mNameIndex;
	private int mSIDIndex;
	private int mActiveIndex;
	
	public SituationCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
			String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
		mSIDIndex= getColumnIndexOrThrow(DBAdapter.DB_Situation_ID);
		mNameIndex  = getColumnIndexOrThrow(DBAdapter.DB_Situation_Name);
		mActiveIndex = getColumnIndexOrThrow(DBAdapter.DB_Situation_Active);
	}

	public String getName() {
		return getString(mNameIndex);
	}

	public int getId() {
		return getInt(mSIDIndex);
	}
	
	public boolean getActive() {
		final int active = getInt(mActiveIndex);
		return (active == DBAdapter.TRUE ? true : false);
	}

}
